import 'package:flutter/material.dart';
import 'package:good_good_study/common/index.dart';
import 'package:good_good_study/pages/home_page.dart';
import 'package:good_good_study/pages/collcet_page.dart';
import 'package:good_good_study/pages/mine_page.dart';
import 'package:good_good_study/provider/current_index_provider.dart';
import 'package:provider/provider.dart';

class IndexPage extends StatelessWidget {

  final items = [
    BottomBarItem(
        icon: Image.asset("images/tabbar_home_normal.png"),
        selectedIcon: Image.asset("images/tabbar_home_selected.png"),
        unSelectedTitle: "首页"),
    BottomBarItem(
        icon: Image.asset("images/tabbar_message_normal.png"),
        selectedIcon: Image.asset("images/tabbar_message_selected.png"),
        unSelectedTitle: "收藏"),
    BottomBarItem(
        icon: Image.asset("images/tabbar_mine_normal.png"),
        selectedIcon: Image.asset("images/tabbar_mine_selected.png"),
        unSelectedTitle: "我的")
  ];

  final pages = <Widget>[HomePage(), CollectPage(), MinePage()];

  @override
  Widget build(BuildContext context) {
    return Scaffold(body: Consumer<CurrentIndexProvider>(
        builder: (context, indexProvider, child) {
      return Column(
        children: [
          Expanded(
            child: IndexedStack(
              children: pages,
              index: indexProvider.currentIndex,
            ),
          ),
          BottomBar(
            currentIndex: indexProvider.currentIndex,
            items: items,
            onTap: (pos) {
              indexProvider.changeIndex(pos);
            },
          )
        ],
      );
    }));
  }

}
